﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using ITim.Controls.Login;
using ITim.Model.Login;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace ITim.ViewModel
{
    public class LoginViewModel : ViewModelBase
    {
        public LoginModel LoginModel { get; set; } = new LoginModel();

        private bool _remeberPwdIsChecked;

        public bool RemeberPwdIsChecked {
            get { return _remeberPwdIsChecked; }
            set { 
                _remeberPwdIsChecked = value;
                this.RaisePropertyChanged();
            }
        }

        private bool _autoLoginIsChecked;

        public bool AutoLoginIsChecked {
            get { return _autoLoginIsChecked; }
            set {
                _autoLoginIsChecked = value;
                this.RaisePropertyChanged();
                if (_autoLoginIsChecked) {
                    RemeberPwdIsChecked = true;
                }
            }
        }


        #region 登录
        private ICommand _loginCommand;

        public ICommand LoginCommand
        {
            get
            {
                if (_loginCommand == null)
                    _loginCommand = new RelayCommand<object>(x =>
                    {
                        if (LoginModel.QQLoginCheck)
                        {
                            var popup = x as System.Windows.Controls.Primitives.Popup;
                            if (popup!=null)
                                popup.IsOpen = true;
                        }
                        else
                        {
                            LoginModel.LoginWayControl = new QQLoginControl();
                        }
                    });
                return _loginCommand;
            }
        }
        #endregion


        public LoginViewModel()
        {
            LoginModel.UserModel = new Model.UserModel()
            {
                UserName = "0009999",
                Password = "0ljljll"
            };

            LoginModel.UserInfosRecord = new System.Collections.ObjectModel.ObservableCollection<Model.UserModel>()
            {
                new Model.UserModel(){UserName="check1",Password="111111"},
                new Model.UserModel(){UserName="check4",Password="111111"}
            };
            LoginModel.QQLoginCheck = true;
        }
    }
}
